package com.yzy.domain.strategy.model.entity;

import org.apache.commons.lang3.StringUtils;

import com.yzy.types.common.Constants;
import com.yzy.types.common.Constants.RuleKey;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author yangzhenyu05 <yangzhenyu05@kuaishou.com>
 * Created on 2024-01-12
 * @description 策略实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StrategyEntity {
    /**
     * 策略ID
     */
    private Long strategyId;
    /**
     * 抽奖策略描述
     */
    private String strategyDesc;
    /**
     * 抽奖策略模型【rule_weight，rule_blacklist】
     */
    private String ruleModels;

    /**
     * @return 返回抽奖策略规则模型
     */
    public String[] ruleModels() {
        if (StringUtils.isBlank(ruleModels)) {
            return null;
        }
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight() {
        String[] ruledModels = this.ruleModels();
        for (String ruledModel : ruledModels) {
            if (ruledModel.equals(RuleKey.RULE_WEIGHT_KEY)) {
                return ruledModel;
            }
        }
        return null;
    }
}
